<template>
	<div>
		<el-table ref="multipleTable" :data="tableData" stripe row-key="id" style="width: 100%" @selection-change="handleSelectionChange">
			<el-table-column type="selection" width="55" reserve-selection></el-table-column>
			<el-table-column prop="title" label="题干" show-overflow-tooltip>
				<template slot-scope="{ row }">
					<span v-html="row.testSubjects.title"></span>
				</template>
			</el-table-column>
			<el-table-column prop="type" label="类型" width="100">
				<template slot-scope="{ row }">
					<span>{{ typeFilter(row.testSubjects.type) }}</span>
				</template>
			</el-table-column>
			<el-table-column prop="difficulty" label="难度" width="100">
				<template slot-scope="{ row }">
					<span>{{ difficultyFilter(row.testSubjects.difficulty) }}</span>
				</template>
			</el-table-column>
			<el-table-column prop="errClassId" label="分类" width="100">
				<template slot-scope="{ row }">
					<span>{{ row.errClassId && row.sysClassify ? row.sysClassify.name : '--' }}</span>
				</template>
			</el-table-column>
			<el-table-column prop="createTime" label="创建时间" width="180"></el-table-column>

			<el-table-column label="操作" width="100">
				<template slot-scope="{ row }">
					<el-button-group>
						<el-button type="success" size="mini" @click="handlePreview(row)">查看</el-button>
					</el-button-group>
				</template>
			</el-table-column>
			<div slot="empty" class="emptyBg">
				<el-empty :image-size="200"></el-empty>
			</div>
		</el-table>
		<Pagination v-show="parseInt(pageObj.count) > 0" :total="parseInt(pageObj.count)" @change="getList" :page.sync="listQuery.page" :limit.sync="listQuery.limit" />
		<Classify />
	</div>
</template>
<script>
import questionMixin from '@/views/Admin/exam/public/questionMixin';
export default {
	mixins: [questionMixin],
	components: {
		Classify: () => import('./Classify.vue')
	},
	data() {
		return {
			listQuery: {
				page: 1,
				limit: 10,
				subjectsName: '',
				isAll: 'N'
				// createBy: this.$store.getters.userId
			},
			tableData: [],
			pageObj: {}
		};
	},
	computed: {},
	mounted() {
		this.getList();
		this.$bus.$on('refreshTestErrorClassifyList', (v) => {
			Object.assign(this.listQuery, v);
			this.getList();
		});
		this.$bus.$on('clearSelected', this.finishClassify);
	},
	beforeDestroy() {
		this.$bus.$off('refreshTestErrorClassifyList');
		this.$bus.$off('clearSelected');
	},
	methods: {
		async getList() {
			let res = await this.$store.dispatch('queryTestSubjectsError', this.listQuery);
			this.tableData = res.data;
			this.pageObj = res;
		},
		//批量操作
		handleSelectionChange(val) {
			this.$bus.$emit('testSubjectsErrorArr', val);
		},
		//预览
		handlePreview(row) {
			this.$bus.$emit('showDialogTestError', row);
		},
		//分类
		handleClassify(row) {
			this.$bus.$emit('showDialogTestErrorClassify', row);
		},
		//删除
		handleDelete(row) {
			this.$confirm('确定要删除吗?', '提示', {
				confirmButtonText: '删除',
				cancelButtonText: '取消',
				type: 'warning'
			})
				.then(() => {
					this.delete(row);
				})
				.catch(() => {});
		},
		async delete(row) {
			await this.$store.dispatch('delTestSubjectsError', row);
			this.getList();
		},
		finishClassify() {
			this.getList();
			this.$refs.multipleTable.clearSelection();
		}
	}
};
</script>
<style scoped lang="scss"></style>
